﻿@model PInitiatives.ViewModels.VMInitiative.VMInitiativeDetails
@{
    ViewBag.Title = "ivent: " + @Html.DisplayFor(model => model.Initiative.Name);
}
<!-- Nazwa Inicjatywy -->
<p>
<div class="row-fluid">

    <div class="span8">

    <h3>@Html.DisplayFor(model => model.Initiative.Name)</h3>
    </div>

    <div class="span4 left">
     <h3>
     @if (Model.isAuthor)
     {
        <i class="icon-cog "></i>  @Html.ActionLink("Edytuj", "Edit", new { id = Model.Initiative.ID })
     }
     </h3>

     </div>
   </div>
</p>
<!-- Status inicjatywy -->
@if (Model.Initiative.State == "Finished")
{
    <div class="alert alert-grey">
        Ivent się zakończył:<strong> @Html.DisplayFor(model => model.Initiative.StartDate)</strong>
    </div>
 
}
else if (Model.Initiative.State == "Canceled")
{
    <div class="alert alert-error">
        Ivent został anulowany.
    </div>
}
else
{ 
    <div class="alert alert-success">
        <div class="row-fluid ">
            <div class="span6 ini-flat">
      
                    Status: <strong>@Html.DisplayFor(model => model.Initiative.State)</strong>
            </div>
            <div class="span6 ini-flat">
               
                    <i class="icon-calendar"></i> <strong>@Html.DisplayFor(model => model.Initiative.StartDate)</strong>
            </div>
        </div>
    </div>
}
<!-- /////////////////////////////////////////////////////////////////////////////////// -->
<div class="row-fluid">
    <!-- lewa kolumna -->
    <div class="span6">
        <!-- Detale nt inicjatywy -->
        <div class="row-fluid show-grid-left">
            <div class="span12">
                
                <center>Ilość Miejsc: <strong>@Html.DisplayFor(model => model.Initiative.Limit)</strong></center>

                <br/>
                <strong>Opis:</strong><br/>
                <div class="alert alert-plain">
                     <div class="row-fluid">
                     
                @Html.DisplayFor(model => model.Initiative.Description)
                    </div>
                </div>
                
                
                <!--
                <br />
                Categories: <strong>@Html.DisplayFor(model => model.Initiative.Categories.Name)</strong>
                <br />
                -->

                <strong>Uczestniczący: (@Model.Initiative.getInitiativeUsers("Participated").Count().ToString()/@Html.DisplayFor(model => model.Initiative.Limit))</strong><br/>
                 <div class="alert alert-plain">
                     <div class="row-fluid">
                     
                        <strong>
                        @foreach (var item in Model.Initiative.getInitiativeUsers("Participated"))
                        {    

                            @Html.DisplayFor(modelItem => item.UserName)                            
                                <br/>
                        }
                        </strong>
                    </div>
                </div>

                
             
            </div>
        </div>
    </div>
    <!-- prawa kolumna -->
    <div class="span6">
        <!-- Info o autorze -->
        <div class="row-fluid show-grid-left">
            <div class="span12">
                Data Utworzenia: <strong>@Html.DisplayFor(model => model.Initiative.CreateDate)</strong><br/>
                Autor: <strong>@Html.DisplayFor(model => model.Initiative.InitiativeAuthor.UserName) (@Html.DisplayFor(model => model.Initiative.InitiativeAuthor.Rate))</strong>
                <br />
                Anulowane iventy: <strong>@Html.DisplayFor(model => model.Initiative.InitiativeAuthor.CanceledInitiativesCount)</strong>
            </div>
        </div>
        <br />
        <!-- Przyciski akcji -->
        <div class="row-fluid show-grid-left">
            <div class="span12">

                <div class="alert">

                    Możliwość rezygnacji do:<br/><strong>@Html.DisplayFor(model => model.Initiative.FreeResignDate)</strong>
                </div>


                
                @if (Model.isAuthor && Model.Initiative.State != "Finished" && Model.Initiative.State != "Canceled")
                {
                    <br/>
                    

                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "finish")
                        @Html.HiddenFor(model => model.Initiative.ID)
                            <button type="submit" class="btn ini-green-btn" ><i class="icon-off icon-white"></i> Zakończ</button>
                    </fieldset>
                    }

                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "cancel")
                        @Html.HiddenFor(model => model.Initiative.ID)
                            <button type="submit" class="btn ini-green-btn" ><i class="icon-remove icon-white"></i> Anuluj Inicjatywę</button>
                    </fieldset>
                    }
                }
                //jeśli uczestnik
                else if (Model.participates)
                {

                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "resign")
                        @Html.HiddenFor(model => model.Initiative.ID)
                        <button type="submit" class="btn ini-green-btn" onclick="return conf('@Model.Initiative.FreeResignDate');"><i class="icon-share icon-white"></i> Zrezygnuj z Uczestnictwa</button>
                        <!--<input type="submit" value="Rezygnuję." onclick="return conf('@Model.Initiative.FreeResignDate');"/>-->
                    </fieldset>
                    }
                }
                //Jeśli brak miejsc
                else if (Model.Initiative.Limit <= Model.Initiative.getInitiativeUsers("Participated").Count())
                {
                    <div class="alert alert-info">
                        <div class="row-fluid">
                            Niestety nie ma już miejsc na ten ivent
                        </div>
                    </div>

                }
                //Jeśli nie zapisany użytkownik
                else if (!Model.participates && Model.Initiative.State != "Finished" && Model.Initiative.State != "Canceled")
                {
                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "participate")
                        @Html.HiddenFor(model => model.Initiative.ID)
                        <button type="submit" class="btn ini-green-btn" ><i class="icon-edit icon-white"></i> Dołącz się do iventu!</button>
                    </fieldset>
                    }

                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "check")
                        @Html.HiddenFor(model => model.Initiative.ID)
                        <button type="submit" class="btn ini-green-btn" name="btnSubmit" value="CheckInCalendar" ><i class="icon-calendar icon-white"></i>Sprawdź w kalendarzu</button>
                        
                    </fieldset>
                    }
                    
                    using (Html.BeginForm())
                    {
    
                    @Html.ValidationSummary(true)
                    <fieldset>
                        @Html.Hidden("choice", "check")
                        @Html.HiddenFor(model => model.Initiative.ID)
                        <button type="submit" class="btn ini-green-btn" name="btnSubmit" value="SendEmail" ><i class="icon-calendar icon-white"></i>Wyślij wiadomość do autora</button>
                        
                    </fieldset>
                    }
                }
            </div>
        </div>
    </div>
</div>

<!-- /////////////////////////////////////////////////////////////////////////////////// -->
<!-- Użytkownicy -->
<div class="row-fluid show-grid">

    <div class="span12">
    <h4>Uczestnicy</h4>
        @{
            var users = new WebGrid(
                source: Model.Initiative.getInitiativeUsers("Participated"),
                canPage: true,
                canSort: true,
                rowsPerPage: 20,
                defaultSort: "Name",
                ajaxUpdateContainerId: "usersGrid"
                );

        }
        @users.GetHtml(htmlAttributes:
                new { id = "usersGrid" },
                tableStyle:
                    "ini-table-black",
                columns:
                    users.Columns(
                        users.Column(
                            columnName: "Name",
                            header: "Nazwa",
                            format: item => @Html.ActionLink((string)item.UserName, "Profile", "Account", new { id = item.ID }, new { title = item.FirstName + " " + item.LastName })
                         ),
                        users.Column(
                            columnName: "columnNameTeKSt",
                            header: "Statystyki (Nieobecność / Rezygnacja w ostatniej chwili / Zmiana decyzji)",
                            format: item => (string)(item.AbsencesCount.ToString() + "/" + item.LMResignationsCount.ToString() + "/" + item.ResignationsCount.ToString())
                //format: item => @Html.Display(string)(item.AbsencesCount.ToString() + "/" + item.LMResignationsCount.ToString() + "/" + item.ResignationsCount.ToString()))
                        )
                    )
                )<!-- Użytkownicy -->
        <!-- Oceny inicjatywy -->
    </div>
</div>
          
     <div class="row-fluid">
        <div class="span12">  

     @if (Model.Initiative.State == "Finished")
     {

     <h4>Oceny Uczestników:</h4>
         var reviews = new WebGrid(
             source: Model.Reviews,
             canPage: true,
             canSort: true,
             rowsPerPage: 20,
             defaultSort: "RatingUserID",
             ajaxUpdateContainerId: "usersGrid"
             );

            @reviews.GetHtml(htmlAttributes:
                new { id = "usersGrid" },
                tableStyle: "ini-table-black",
                    columns: reviews.Columns(
                             reviews.Column(
                                        columnName: "RatingUserID",
                                        header: "Oceniający",
                                    format: item => item.RatingUserID.ToString()
                                  ),
                                  reviews.Column(
                                              columnName: "InitiativeRate",
                                              header: "Ocena",
                                          format: item => item.InitiativeRate

                                      ),
                            reviews.Column(
                                        columnName: "Description",
                                        header: "Opinia",
                                    format: item => item.Description

                            )
                            )
                    )

     }

    </div>
</div>
<br/>
<br/>
<!-- facebook -->
<div class="row-fluid show grid">
    <div class="span12">
        <iframe src="http://www.facebook.com/plugins/like.php?href=http://stosowana.pl" scrolling="no"
            frameborder="0" style="border: none; width: 450px; height: 40px"></iframe>
    </div>
</div>
<div style="border-bottom: 1px solid #DDD;">
</div>
<p>
    @Html.ActionLink("Powrót do Kategorii", "Index")
</p>
<script type="text/javascript">
    function conf(FRDate) {
        var date = new Date();
        var dateString = date.getFullYear() + '-';
        if (date.getMonth() < 9)
            dateString += '0';
        dateString += (date.getMonth() + 1) + '-';
        if (date.getDate() < 10)
            dateString += '0';
        dateString += date.getDate() + ' ';
        if (date.getHours() < 10)
            dateString += '0';
        dateString += date.getHours() + ':';
        if (date.getMinutes() < 10)
            dateString += '0';
        dateString += date.getMinutes() + ':';
        if (date.getSeconds() < 10)
            dateString += '0';
        dateString += date.getSeconds();

        if (FRDate < dateString)
            alert("Minął już free-resign time!");
        if (confirm("Na pewno chcesz zrezygnować?"))
            return true;
        else
            return false;
    }
</script>
